<template>
    <div class="mark-detail">
        
        <el-dialog
        title="新增/编辑"
        :visible.sync="dialogVisible"
        width="25%">
            <el-form label-width="70px"
            :rules="rules" ref="ruleForm" :model="markForm">
                <el-form-item label="名称" prop="name">
                    <el-input v-model="markForm.name"></el-input>
                </el-form-item>
                <el-form-item label="说明" prop="note" >
                    <el-input v-model="markForm.note"></el-input>
                </el-form-item>
                <el-form-item label="图片">
                    <!-- <el-input v-model="item.img"></el-input> -->
                    <!-- <image-uploader v-model="markForm.img" /> -->
                </el-form-item>
                
                
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
// import ImageUploader from './ImageUploader';
import product from '../../api/product';

export default {
    // components: {
    //     ImageUploader
    // },
    data() {
        return {
            dialogVisible: false,
            markForm: {
                id: null,
                name: '',
                note: '',
                img: ''
            },
            rules: {
                name: [
                    { required: true, message: '请输入名称', trigger:'blur'},
                ],
            },

        };
    },
    methods: {
        show(item) {
            if (item) {
                this.markForm = item;
            } else {
                this.markForm = {};
            }
            this.dialogVisible = true;
        },
        hide() {
            this.dialogVisible= false;
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid)=>{
                if (valid) {
                    product.saveMark({mark: this.markForm}).then(res=>{
                        this.$notify({
                            title: '成功',
                            message: res.message,
                            type: 'success'
                        });
                        this.hide();
                        this.$emit('update');
                    });
                } else {
                    return false;
                }
            });
            
        },
        
    },
};
</script>

<style>
    
</style>